home *** CD-ROM | disk | FTP | other *** search
- ' This control implements a ribbon of four hyperlinks, and can be used
- ' to navigate through a number of pages.
-
- Imports System.ComponentModel
- Imports System.Web.UI
-
- <ToolboxData("<{0}:NavigateRibbon runat=server></{0}:NavigateRibbon>")> _
- Public Class NavigateRibbon
- Inherits System.Web.UI.WebControls.WebControl
- Implements IPostBackEventHandler
-
- ' The PageCount property.
- <Description("The number of pages")> _
- Property PageCount() As Integer
- Get
- Dim o As Object = Me.ViewState("PageCount")
- If o Is Nothing Then
- ' return the default PageCount value
- Return 100
- Else
- Return CInt(o)
- End If
- End Get
- Set(ByVal Value As Integer)
- Me.ViewState("PageCount") = Value
- End Set
- End Property
-
- ' The PageNumber property.
-
- <Description("The current page number")> _
- Property PageNumber() As Integer
- Get
- Dim o As Object = Me.ViewState("PageNumber")
- If o Is Nothing Then
- Return 1 ' the default value
- Else
- Return CInt(o)
- End If
- End Get
- Set(ByVal Value As Integer)
- Me.ViewState("PageNumber") = Value
- End Set
- End Property
-
- ' this is where the actual code is produced
-
- Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
- Dim items() As String = {"First", "Previous", "Next", "Last"}
-
- Dim s As String
- For Each s In items
- ' Create the <A HREF="javascript:__doPostBack(....)"> tag
- output.AddAttribute("id", Me.ClientID)
- output.AddAttribute("href", "javascript:" & Page.GetPostBackEventReference(Me, s))
- output.RenderBeginTag("a")
- ' Display the caption.
- output.Write(s)
- ' Close the tag.
- output.RenderEndTag()
- ' Add a couple of spaces.
- output.Write(" ")
- output.Write(" ")
- Next
- End Sub
-
- ' this method is called when one of the hyperlinks is clicked
-
- Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
- Dim pageNum As Integer = PageNumber
-
- ' update the page number
- Select Case eventArgument.ToLower
- Case "first"
- pageNum = 1
- Case "previous"
- pageNum = Math.Max(pageNum - 1, 1)
- Case "next"
- pageNum = Math.Min(pageNum + 1, PageCount)
- Case "last"
- pageNum = PageCount
- End Select
-
- ' raise an event in the client if a new page is being shown
- If PageNumber <> pageNum Then
- PageNumber = pageNum
- OnPageChanged(EventArgs.Empty)
- End If
- End Sub
-
- ' this is a public event that takes no extra arguments
- Event PageChanged As EventHandler
-
- ' derived controls should override this method to control
- ' whether the PageChanged event should be send to their clients
-
- Protected Overridable Sub OnPageChanged(ByVal e As EventArgs)
- RaiseEvent PageChanged(Me, e)
- End Sub
-
- End Class
-
-